import {defineConfig, loadEnv} from 'vite'
import vue from '@vitejs/plugin-vue'
// import { join } from 'path'
import path from "path";
import obfuscator from 'rollup-plugin-obfuscator';

function resolve(dir) {
    return path.join(__dirname, dir);
}

// 判断当前是否为生产环境
export default ({mode}) => {
    const env = loadEnv(mode, process.cwd());
    const isProduction = env.VITE_NODE_ENV === 'production';

    return defineConfig({
        plugins: [
            isProduction && obfuscator({
                options: {
                    include: ['*/entries/others/index.js']
                },
            }),
            vue(),
        ],
        resolve: {
            alias: {
                "@": resolve("src")
            },
        },
        define: {
            "process.env": {},
        },
        base: env.VITE_APP_ALD_OTHER_BASE,
        build: {
            outDir: 'dist/xsbh5',
            assetsDir: 'static_other',
            rollupOptions: {
                input: {
                    down: 'other.html'
                },
            }
        },
        server: {
            open: true,
            host: "0.0.0.0",
            proxy: {
                '/xsb': {
                    target: env.VITE_APP_ALD_SERVER,  //后台的地址
                    changeOrigin: true,
                },
            }
        }
    })
}
